home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / shell / csh540src.lha / technotes.doc < prev    next >
Text File  |  1991-10-31  |  4KB  |  90 lines

  1.         TECHINCAL NOTES FOR CSHELL
  2.         ==========================
  3.  
  4.  
  5. THE PARSER
  6. ----------
  7.  
  8. The  heart  of  CShell  is the parser.  It was, I suppose, originally taken
  9. from a UNIX csh. It does its job in two steps:
  10.  
  11. First  comes  the  preformatting,  which is done while copying the original
  12. line  to  a temporary buffer.  It is important to make a difference between
  13. quoted  and  and  unquoted characters.  Earlier shell versions of the shell
  14. set  the  most  significant  bit  of quoted chars, but this made the use of
  15. international  character  sets  impossible.   Now  it's  done the other way
  16. round:   Every _unquoted_ char with special meaning (e.g.  the asterisk) is
  17. replaced  by  a number between 128 and 159.  Ascii code 160 is used as word
  18. separator in strings (so words may contain blanks).
  19.  
  20. After  the preformatting is done, the parser's main task is building up the
  21. argument  array  av[i]  for  the internal and external commands.  Memory is
  22. allocated  for  every argument and the argument is put together from one or
  23. more  tokens  (e.g.   $a$b).  After av[0] has been completed, certain flags
  24. are  set  in  order  to  do  things  like preventing wild card expinsion of
  25. arguments to 'dir'.
  26.  
  27. Then,  with the argument line is complete, the aliases list is searched for
  28. a  name that matches av[0].  If it exists, the parser is called recursively
  29. with  the  alias's  command line.  Recursive calls of the parser (using the
  30. function  execute()) have no more side effects at all since version 5.1 and
  31. can therefore used to do things like automatic cd and class features.
  32.  
  33. In  order to speed up this process with many allocations and deallocations,
  34. I  have  written  a  custom  storage  allocator.   It  allocates  groups of
  35. 1000-byte-blocks  (called  frames)  using malloc() and then distibutes them
  36. until  they're  used  up.  Of course, deallocation of single allocations is
  37. not  possible,  only  the  frame as a whole can be deallocated.  But that's
  38. okay, since all temporaries are deallocated when the parser is left.
  39.  
  40.  
  41. THE BUILTINS
  42. ------------
  43.  
  44. The other side of the shell are the built in commands.  They look much like
  45. CLI commands in C, but they have lots of support functions for their needs.
  46.  
  47. To  write a builtin command for CShell, you use the global variables av and
  48. ac  instead of argv and argc, and use printf() for output.  That's it.  Any
  49. other changes, if necessary, will be done by me.
  50.  
  51. Every  builtin  command  has its equivalent as a C function with the prefix
  52. do_ (example:  do_addbuffers).  The are no hard coded jumps to any of those
  53. functions,  instead there is a table with the descriptions of all functions
  54. (like  name, usage, minimum arguments and, last but not least, a pointer to
  55. that function).
  56.  
  57.  
  58. WHY BUILT IN COMMANDS?
  59. ----------------------
  60.  
  61. The reasons why C-Shell still relies heavily on internal commands:
  62. - They can take advantage from each other (e.g. class recognition in the
  63.   'dir' command, use of 'search' command in quick cd)
  64. - They have a fast calling sequence
  65. - They need no hard disk seeks, so the startup can be accelerated
  66.   significantly
  67. - They are shorter than external commands
  68. - And finally, if you don't like them, don't use them. The wasted resources
  69.   become more and more negligible nowadays... CShell uses 2% of my memory.
  70.  
  71.  
  72. SOURCES
  73. -------
  74.  
  75. The  source  for CShell is available, if you don't have it, request it from
  76. me.   It consists of 10 modules, together 200K.  It is compilable under SAS
  77. (Lattice)  &  Manx  C,  although  the  executables produced by Manx are not
  78. residentable.   If you want to modify it, ask me for an up-to-date version
  79. first.   You  may  not  release  modified  versions  (imagine  the chaos if
  80. everbody  releases his private csh), but if you send them to me, you have a
  81. good  chance  that I'll build it in.  You'll be, of course, be mentioned in
  82. the docs.
  83.  
  84. Even  if  you  don't  intend to modify it, I still encourage you to get the
  85. source,  because  there  are  so many things you can look up there once you
  86. need them (did *you* know how to set the system date?).  I apologize for my
  87. poor to nonexistent comments, I'll go through again when I've got the time.
  88. Ah,  yes,  that  famous  Dillon-formatting  is gone, now it's traditionally
  89. formatted.
  90.